using System;
using System.Linq;
using System.Collections.Generic;

namespace HashFoo.Core
{
    /// <summary>
    /// Date/Time utility functions.
    /// </summary>
    public static class DateTimeUtil
    {
        /// <summary>
        /// Converts a <see cref="DateTime"/> to a UTC <see cref="DateTimeOffset"/>.
        /// If the DateTime has Kind of Local, it is converted to UTC.  Else, it is assumed to be in UTC.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static DateTimeOffset AsUtcDateTimeOffset(this DateTime value)
        {
            var dateToConvert = value.Kind == DateTimeKind.Local ? value.ToUniversalTime() : value;

            return new DateTimeOffset(dateToConvert, TimeSpan.FromHours(0));
        }
    }
}